<template>
  <page-wrap stayStill back title="活动详情" hideTab>
    <view class="container">
      <u-image :src="headerImg" :lazy-load="true" width="100%" :height="headerHeight"></u-image>

      <Activity1 v-if="sharePersonId.length > 0" :sharePersonId="sharePersonId" :activityId="activityId"></Activity1>
      <view v-else>
        <view class="sctionBtn">
          <u-subsection height="100" :list="sectionList" :current="sectionIndex" @change="sectionChange"></u-subsection>
        </view>
        <swiper class="swiper-box" :style="{ minHeight: swiperHeight }" :duration="200" :current="sectionIndex"
          @transition="handleTransition" @animationfinish="handleAnimation">
          <swiper-item class="swiper-item">
            <Activity1 :activityId="activityId" :inputValue="popupInputText" @didClicPopupRecode="handlePopupClick"
              @clickInputPopup="showInputPopup"></Activity1>
          </swiper-item>
          <swiper-item class="swiper-item">
            <ActivityPage @didClick="handlePopupLogClick"></ActivityPage>
          </swiper-item>
        </swiper>
      </view>

      <PopupPageRecode :show="isShowRecodePopup" :prizeMines="prizeMines" :prizeWheels="prizeWheels"
        @didClick="handlePopupLogClose"></PopupPageRecode>
      <PopupPageOne :show="isShowPopupRecode" :datas="opupRecodeDatas" @didClick="handlePopupClose"></PopupPageOne>
      <PopupInputAlert :show="isShowInputPopup" :prizeCode="prizeCode" @didClick="clickPopupInputAlert"
        @didClose="clickPopupInputClose"></PopupInputAlert>
    </view>
  </page-wrap>
</template>

<script>
// import { getZphActAssistance } from '@/api/modules/zph.js';
import Activity1 from "./components/Activity1.vue";
import ActivityPage from "./components/ActivityPage.vue";
import ShareMixin from "@/mixins/share";
import PopupPageOne from "./components/PopupPageOne.vue";
import PopupInputAlert from "./components/PopupInputAlert.vue";
import PopupPageRecode from "./components/PopupPageRecode.vue";

export default {
  mixins: [ShareMixin],
  components: {
    Activity1,
    ActivityPage,
    PopupPageOne,
    PopupInputAlert,
    PopupPageRecode,
  },
  data() {
    return {
      activityId: "",
      headerImg: this.$imgBaseSelf + "zph/activityBg0.png",
      headerHeight: 0,
      personId: uni.getStorageSync("person-id").slice(2) || "",
      sectionIndex: 1,
      sectionList: [
        {
          name: "助力抢红包",
        },
        {
          name: "好礼抽不停",
        },
      ],

      isLoading: false,
      sharePersonId: "", // 19587250 , 19588506

      isShowPopupRecode: false,
      opupRecodeDatas: [],

      isShowInputPopup: false,
      prizeCode: "",
      popupInputText: "",

      isShowRecodePopup: false,
      prizeWheels: [],
      prizeMines: [],
    };
  },

  onLoad(opt) {
    console.log("🚀 ~ zphActivity.onLoad~ opt:", opt);
    if (opt) {
      this.activityId = opt.activityId;
      if (opt.sharePersonId && opt.sharePersonId.length > 0) {
        if (opt.sharePersonId != this.personId) {
          this.sharePersonId = opt.sharePersonId;
        }
      }
    }
  },

  onShow() {
    console.log("活动页面 - onshow");
  },

  mounted() {
    console.log("活动页面 - mounted");
    this.sharePath = "/pagesSub/careerGrow/zph/zphActivity";
    this.getHeaderHeight();
  },

  methods: {
    //////////////// 弹窗的事件处理 bging //////////////

    // 去领取 - 弹窗输入
    showInputPopup(code) {
      this.isShowInputPopup = true;
      this.prizeCode = code;
    },
    clickPopupInputAlert(input, code) {
      this.popupInputText = input;
      this.isShowInputPopup = false;
    },
    clickPopupInputClose() {
      this.isShowInputPopup = false;
    },

    // 领取记录 - 弹窗信息
    handlePopupClick(items) {
      this.opupRecodeDatas = items;
      this.isShowPopupRecode = true;
    },
    handlePopupClose() {
      this.isShowPopupRecode = false;
    },

    // 抽奖记录 - 弹窗信息
    handlePopupLogClick(wheels, mines) {
      this.prizeWheels = wheels;
      this.prizeMines = mines;
      this.isShowRecodePopup = true;
    },
    handlePopupLogClose() {
      this.isShowRecodePopup = false;
    },

    //////////////// 弹窗的事件处理 end //////////////

    sectionChange(index) {
      this.sectionIndex = index;
      if (index == 0) {
        uni.showModal({
          title: "提示",
          content:
            "当前助力活动的奖品全部被抢光了，您可以去招聘会投递简历，参与“好礼抽不停”活动",
          confirmText: "去招聘会",
          confirmColor: "#E18831",
          showCancel: true,
          success: (res) => {
            if (res.confirm) {
              uni.navigateTo({
                url: "/pagesSub/careerGrow/zph/detail?activityId=3281706001460137",
              });
            }
          },
        });
      }
    },
    getGift(item) {
      console.log("领取奖励----", item);
    },
    goShare(param) {
      console.log("分享助力----", param);

      // // 调起分享功能
      // uni.share({
      //   provider: 'weixin',
      //   scene: "WXSceneSession",
      //   type: 5,
      //   imageUrl: this.headerImg,
      //   title: "百职万岗春招活动",
      //   miniProgram: {
      //     id: this.personId,
      //     path: res.data.shareUrl,
      //     type: 0,
      //     // webUrl: 'http://uniapp.dcloud.io'
      //   },
      //   success: ret => {
      //     console.log(JSON.stringify(ret));
      //   },
      //   fail: function (err) {
      //     console.log("fail:" + JSON.stringify(err));
      //   }
      // });
    },

    handleTransition(e) {
      // console.log('🚀 ~ handleTransition ~ e:', e.detail.dx);

      return;
      let dx = e.detail.dx;
      this.$refs.tabs.setDx(dx);
    },
    handleAnimation(e) {
      console.log("🚀 ~ handleAnimation ~ e:", e);
      let current = e.detail.current;
      this.sectionIndex = current;
      return;
      // let current = e.detail.current;
      // this.$refs.tabs.setFinishCurrent(current);
      // this.sectionIndex = current;
      // if (this.current == 0) {
      //   this.setListHeight();
      // } else {
      //   this.setAIContentHeight();
      // }
    },

    getHeaderHeight() {
      let width = uni.getSystemInfoSync().windowWidth;
      this.headerHeight = width * (1358 / 1080) + "px";
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  width: 100%;
  background-color: #8484ff;

  .sctionBtn {
    margin-top: -30rpx;
    margin-bottom: 35rpx;
  }
}

.swiper-box {
  min-height: 100vh;
  ::v-deep .uni-swiper-wrapper {
    uni-scroll-view {
      height: 100%;
    }
  }

  .swiper-item,
  .scroll-views {
    height: 100%;
    // background-color: $uni-bg-color;
  }
}
</style>
